package com.bruce.controller;

import com.bruce.domain.Role;
import com.bruce.service.RoleService;
import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(("/role"))
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    public ModelAndView list(){

        ModelAndView modelAndView = new ModelAndView();

        List<Role> roleList = roleService.list();
        // 设置模型
        modelAndView.addObject("roleList", roleList);
        // 设置视图
        modelAndView.setViewName("role-list");
        return modelAndView;
    }

    @RequestMapping("/save")
    public String save(Role role){
        roleService.save(role);
        return "redirect:/role/list";
    }

    @RequestMapping("/del/{roleid}")
    public String del(@PathVariable("roleid") Long roleid){
        roleService.del(roleid);
        return "redirect:/role/list";
    }

}
